﻿using System;
using System.Collections.Generic;
using System.Text;
using Model = SQLServerHealthCheck.Model;
using SQLServerHealthCheck.Model;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using SMO = Microsoft.SqlServer.Management.Smo;
using WMI = Microsoft.SqlServer.Management.Smo.Wmi;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Data.SqlTypes;
using SQLServerHealthCheck.SQLServer.IssueTypes;
using AG.Utilities;

namespace SQLServerHealthCheck.SQLServer
{
    public delegate void RunAllIssueChecks();
    
    public class CheckSQLServerInstancesForIssues
    {
        
        public List<Exception> errors;

        public void RunIssueChecks()
        {

            errors = new List<Exception>();
            //IssueTypesFactory IssueFactory = new IssueTypesFactory();

            List<IssueTypeCheckBase> issueTypesToCheck = IssueTypesFactory.GetAllChecks();
            HealthCheckDataContext dc = new HealthCheckDataContext(System.Configuration.ConfigurationManager.AppSettings["ConnectionStringSSHCDatabase"].ToString());
             
//            var a = from iss in dc.IssueTypes
//                    where iss.Enabled == true
//                    select iss.IssueTypeId;
            foreach (IssueTypeCheckBase issueType in issueTypesToCheck)
            {
                try
                {

//                    if (a.Contains(issueType.IssueTypeId))
//                    {
                        issueType.Check();
//                    }
                  
                }
                catch (Exception ex)
                {
                    errors.Add(ex);
                    Logger.Error(issueType.GetType().FullName,  ex);
                }
               
            }


            


        }
    }
}
